/************************************************************************
Author:			Trey Turley, Thomas Lee, Marc Willis

Filename:		Menu.h

Classname:		Menu

Description:	The menu class allows us to easily print a specific 
				menu to the screen.

Date Modified:	8/8/10
				- File created
************************************************************************/
#ifndef MENU_H
#define MENU_H

#include "Draw.h"
#include <fstream>
#include <string>
#include "GameMap.h"
#include "keyboard.h"
using namespace std;

extern const int SLEEPTIME;

extern const int TITLEX;
extern const int TITLEY;
extern const char TITLECHAR;

class Menu
{
	public:
/************************************************************************
 Name:			Menu()

 Description:	Defualt Constructor

 Input:
 (None)

 Output:
 (None)
*************************************************************************/
		Menu();

/************************************************************************
 Name:			title()

 Description:	Prints the title screen

 Input:
 (None)

 Output:
 (None)
*************************************************************************/
		void title();

/************************************************************************
 Name:			plyrSlct()

 Description:	Menu for selecting number of players

 Input:
 (None)

 Output:
 
 int numPlayers	-	The number of players
*************************************************************************/
		int plyrSlct();

/************************************************************************
 Name:			plyrCtrl(int)

 Description:	Displays the controls for the players

 Input:
 
 int n		-	The number of players	

 Output:
 (None)
*************************************************************************/
		void plyrCtrl(int);

/************************************************************************
 Name:			plyrCtrl(int)

 Description:	Displays the controls for the players

 Input:
 
 int n		-	The number of players	

 Output:
 (None)
*************************************************************************/
		void plyrStrtLoc(int);


/************************************************************************
 Name:			playAgain(bool &)

 Description:	Prints a screen that asks there user(s) if they want to
				play again.

 Input:
 
 bool running - Used to determine if the game should keep running.

 Output:
 (None)
*************************************************************************/
		bool playAgain(bool &,int,int,int,int);

/************************************************************************
 Name:			mapSelect()

 Description:	Prints a screen that asks if they want to use
				the default map or a custom map.

 Input:
 (None)

 Output:
 bool result  - Returns whether or not to load a custom map
*************************************************************************/
		bool mapSelect();

/************************************************************************
 Name:			startGame()

 Description:	Prints the start game timer to the screen.

 Input:
 (None)

 Output:
 (None)
*************************************************************************/
		void startGame();

/************************************************************************
 Name:			pause()

 Description:	pauses the menu. Must press enter to continue.

 Input:
 (None)

 Output:
 (None)
*************************************************************************/
		void pause();

};







Menu::Menu()
{}

/************************************************************************
 Name:			title()

 Description:	Prints the title screen

 Input:
 (None)

 Output:
 (None)
*************************************************************************/
void Menu::title()
{

	//Main Title
	Plotter Title;
	Title.setColor(white);
	Title.move(TITLEX+2,TITLEY+2);
	Title.setColor(blue);
	cout<<TITLECHAR<<TITLECHAR<<TITLECHAR<<TITLECHAR<<TITLECHAR;
	Title.setColor(red);
	cout<<" "<<TITLECHAR<<TITLECHAR<<TITLECHAR<<TITLECHAR<<" ";
	Title.setColor(green);
	cout<<"  "<<TITLECHAR<<TITLECHAR<<TITLECHAR<<" ";
	Title.setColor(yellow);
	cout<<" "<<TITLECHAR<<"   "<<TITLECHAR;
	Title.move(TITLEX+2,TITLEY+3);
	Title.setColor(blue);
	cout<<"  "<<TITLECHAR<<"   ";
	Title.setColor(red);
	cout<<TITLECHAR<<"   "<<TITLECHAR<<" ";
	Title.setColor(green);
	cout<<TITLECHAR<<"   "<<TITLECHAR<<" ";
	Title.setColor(yellow);
	cout<<TITLECHAR<<TITLECHAR<<"  "<<TITLECHAR;
	Title.move(TITLEX+2,TITLEY+4);
	Title.setColor(blue);
	cout<<"  "<<TITLECHAR<<"   ";
	Title.setColor(red);
	cout<<TITLECHAR<<TITLECHAR<<TITLECHAR<<TITLECHAR<<"  ";
	Title.setColor(green);
	cout<<TITLECHAR<<"   "<<TITLECHAR<<" ";
	Title.setColor(yellow);
	cout<<TITLECHAR<<" "<<TITLECHAR<<" "<<TITLECHAR<<" ";
	Title.move(TITLEX+2,TITLEY+5);
	Title.setColor(blue);
	cout<<"  "<<TITLECHAR<<"   ";
	Title.setColor(red);
	cout<<TITLECHAR<<"   "<<TITLECHAR<<" ";
	Title.setColor(green);
	cout<<TITLECHAR<<"   "<<TITLECHAR<<" ";
	Title.setColor(yellow);
	cout<<TITLECHAR<<"  "<<TITLECHAR<<TITLECHAR<<" ";
	Title.move(TITLEX+2,TITLEY+6);
	Title.setColor(blue);
	cout<<"  "<<TITLECHAR<<"   ";
	Title.setColor(red);
	cout<<TITLECHAR<<"   "<<TITLECHAR<<" ";
	Title.setColor(green);
	cout<<TITLECHAR<<"   "<<TITLECHAR<<" ";
	Title.setColor(yellow);
	cout<<TITLECHAR<<"   "<<TITLECHAR<<" ";
	Title.move(TITLEX+2,TITLEY+7);
	Title.setColor(blue);
	cout<<"  "<<TITLECHAR<<"   ";
	Title.setColor(red);
	cout<<TITLECHAR<<"   "<<TITLECHAR<<" ";
	Title.setColor(green);
	cout<<" "<<TITLECHAR<<TITLECHAR<<TITLECHAR<<"  ";
	Title.setColor(yellow);
	cout<<TITLECHAR<<"   "<<TITLECHAR<<" ";
	Title.setColor(white);
	Title.plot(TITLEX,TITLEY,201);
	Title.plot(TITLEX,TITLEY+9,200);
	Title.plot(TITLEX+26,TITLEY,187);
	Title.plot(TITLEX+26,TITLEY+9,188);
	for(int a=1;a<26;a++)
	{
		Title.plot(TITLEX+a,TITLEY,205);
		Title.plot(TITLEX+a,TITLEY+9,205);
	}

	for(int b=1;b<9;b++)
	{
		Title.plot(TITLEX,TITLEY+b,186);
		Title.plot(TITLEX+26,TITLEY+b,186);
	}
	Title.move(34,18);
	cout<<"By:";
	Title.move(34,19);
	cout<<"Thomas Lee";
	Title.move(34,20);
	cout<<"Marc Willis";
	Title.move(34,21);
	cout<<"Trey Turley";

	Title.move(30,24);
	Title.setColor(blue);
	cout<<"Press ";
	Title.setColor(red);
	cout<<"Enter ";
	Title.setColor(green);
	cout<<"To ";
	Title.setColor(yellow);
	cout<<"Play";

	cin.ignore(1000,'\n');
}

/************************************************************************
 Name:			plyrSlct()

 Description:	Menu for selecting number of players

 Input:
 (None)

 Output:
 
 int numPlayers	-	The number of players
*************************************************************************/
int Menu::plyrSlct()
{
	Plotter Title;
	Title.setColor(white);
	int numPlayers;
	bool startGame=false;	

		cout<<"Player colors are:\n";
		Title.setColor(blue);
		cout<<"Player 1: Blue\n";
		Title.setColor(red);
		cout<<"Player 2: Red\n";
		Title.setColor(green);
		cout<<"Player 3: Green\n";
		Title.setColor(yellow);
		cout<<"Player 4: Yellow\n\n";
		Title.setColor(white);

		cout<<"How many human players?";

		numPlayers=-1;
		while(numPlayers==-1){
			if(KEYDOWN(VK_KEY_0)){
				numPlayers=0;
			}
			if(KEYDOWN(VK_KEY_1)){
				numPlayers=1;
			}
			if(KEYDOWN(VK_KEY_2)){
				numPlayers=2;
			}
			if(KEYDOWN(VK_KEY_3)){
				numPlayers=3;
			}
			if(KEYDOWN(VK_KEY_4)){
				numPlayers=4;
			}
		}

		cin.ignore(1000,'\n');

		//cout<<"\n\nPress enter to confirm number of players\n";
	//	this->pause();
		//cin.ignore(1000,'\n');
		


	return numPlayers;

}


/************************************************************************
 Name:			plyrCtrl(int)

 Description:	Displays the controls for the players

 Input:
 
 int n		-	The number of players	

 Output:
 (None)
*************************************************************************/
void Menu::plyrCtrl(int n)
{
		Plotter Title;
		Title.setColor(white);
		cout<<"Player Controls:\n\n";		

		for(int i=1;i<=n;i++)
		{
			
			switch (i)
			{
			case 1:	Title.setColor(blue);
					cout<<"Player 1 will use WASD\n";
					Title.setColor(white);
					break;

			case 2:	Title.setColor(red);
					cout<<"Player 2 will use the Arrow Keys\n";										
					Title.setColor(white);		
					break;

			case 3:	Title.setColor(green);
					cout<<"Player 3 will use IJKL\n";					
					Title.setColor(white);				
					break;

			case 4:	Title.setColor(yellow);
					cout<<"Player 4 will use 8456\n";
					Title.setColor(white);
					break;
			};
		}		


		cout<<"\nPress enter to continue\n";
		//this->pause();
		cin.ignore(1000,'\n');
}


/************************************************************************
 Name:			playAgain(bool &)

 Description:	Prints a screen that asks there user(s) if they want to
				play again.

 Input:
 
 bool running - Used to determine if the game should keep running.

 Output:
 (None)
*************************************************************************/
bool Menu::playAgain(bool &running,int p1,int p2,int p3,int p4)
{
	Plotter scrn;
	scrn.clear();
	scrn.move(0,0);
	scrn.setColor(white);
	cin.ignore(10000,'\n');
	scrn.clear();
	cout<<"Play again(Y/N)?";	

	bool yesno=false;
	while(!yesno)
	{
		if(KEYDOWN(VK_KEY_N))
		{
			running=false;
			yesno=true;
			cin.ignore(10000,'n');
		}
		if(KEYDOWN(VK_KEY_Y))
		{
			yesno=true;
			cin.ignore(10000,'y');
		}
	}
	
	cin.ignore(10000,'\n');


	if(!running)
	{
		cout<<"Player 1 had "<<p1<<" win(s)"<<endl;
		cout<<"Player 2 had "<<p2<<" win(s)"<<endl;
		cout<<"Player 3 had "<<p3<<" win(s)"<<endl;
		cout<<"Player 4 had "<<p4<<" win(s)"<<endl;
		cout<<"Press enter to quit";
		cin.ignore(10000,'\n');
	}

	
	

	return running;
}

/************************************************************************
 Name:			mapSelect()

 Description:	Prints a screen that asks if they want to use
				the default map or a custom map.

 Input:
 (None)

 Output:
 bool result  - Returns whether or not to load a custom map
*************************************************************************/
bool Menu::mapSelect()
{
	//cin.ignore(numeric_limits<streamsize>max(), '\n');


	bool result=false;
	int num=-1;
	Plotter scrn;
	scrn.clear();
	scrn.setColor(white);
	scrn.move(0,0);

	cout<<"Would you like to load a custom game map?\n";
	cout<<"Enter 0 for No and 1 for Yes\n";

	//cin.ignore(1000,'\n');
	

		while(num==-1){
			if(KEYDOWN(VK_KEY_0)){
				num=0;
			}
			if(KEYDOWN(VK_KEY_1)){
				num=1;
				result=true;
			}			
		}			
		
		cin.ignore(10000,'\n');
		//cout<<"Press enter to continue";
		//cin.ignore(1000, '\n');
			
		return result;
}



/************************************************************************
 Name:			startGame()

 Description:	Prints the start game timer to the screen.

 Input:
 (None)

 Output:
 (None)
*************************************************************************/
void Menu::startGame()
{
	cout<<"\n\nThe Game Begins in: ";
	for(int t=5;t>0;t--)
	{
		cout<<t<<" ";
		Sleep(1000);
	}
	cout<<"GO!";
	Sleep(250);
}


/************************************************************************
 Name:			pause()

 Description:	pauses the menu. Must press enter to continue.

 Input:
 (None)

 Output:
 (None)
*************************************************************************/
void Menu::pause()
{
	while(!(KEYDOWN(VK_RETURN)));
	cin.clear();
}


#endif
